<script type="text/javascript" src="/bootstrap_datetimepicker/bootstrap-datetimepicker.js"></script>
<link rel="stylesheet" type="text/css" href="/bootstrap_datetimepicker/bootstrap-datetimepicker.css">
<script type="text/javascript" src="/bootstrap_datetimepicker/bootstrap-datetimepicker.zh-CN.js"></script>
<style>
    .table>thead>tr>th{background: #ddd;}
    .table>tbody>tr>td ,.table>thead>tr>th{padding:8px;line-height:2;vertical-align:bottom;border-bottom:1px solid #ddd;}
    .col-md-12{background:#ffffff;}
    .form-inline>button{height: 40px;width: 100px;font-size: 16px;}
    .form-inline .form-group>input{border-radius:3px;}
    .modal-body .form-group>label{margin-left: 20px;float:left;margin-right: 10px;padding-top: 8px;width: 150px;}
    .modal-body .form-group>input{width: 65%;}
    #time_start{margin-left:20px;width: 250px;height: 40px;}
    #reset{margin-left: 10px;}
</style>
<body>
<form class="form-inline" role="form" style="margin-top: 20px;margin-bottom: 20px;">
    <div class="form-group" style="width: 350px;">
        <input type="text" class="form-control" id="time_start" autocomplete="off" value="<?php if(!empty($_GET['created_at'])){echo $_GET['created_at'];}?>" placeholder="请选择推送时间">
    </div>
    <button type="button" class="btn btn-primary" id="select">查询</button>
    <button type="button" class="btn btn-default" id="reset">重置</button>
</form>

<table class="table table-hover">
    <thead>
    <tr>
        <th>药品名称</th>
        <th>早餐前剂量</th>
        <th>中餐前剂量</th>
        <th>晚餐前剂量</th>
        <th>睡前剂量</th>
        <th>推送时间</th>
    </tr>
    </thead>
    <tbody>
    @foreach ($result as $item)
        <tr>
            <td>{{$item->insulin_name_cn}}</td>
            <td>
                @if(!empty($item->insulin['before_breakfast']))
                    {{$item->insulin['before_breakfast']}}
                @else
                    -
                @endif
            </td>
            <td>
                @if(!empty($item->insulin['before_lunch']))
                    {{$item->insulin['before_lunch']}}
                @else
                    -
                @endif
            </td>
            <td>
                @if(!empty($item->insulin['before_dinner']))
                    {{$item->insulin['before_dinner']}}
                @else
                    -
                @endif
            </td>
            <td>
                @if(!empty($item->insulin['before_sleep']))
                    {{$item->insulin['before_sleep']}}
                @else
                    -
                @endif
            </td>
            <td>{{$item->created_at}}</td>
        </tr>
    @endforeach
    </tbody>
</table>
{{ $result->links() }}

</body>

<script>
    $('#reset').click(function () {
        $('#time_start').val('');
    });

    $('#select').click(function () {
        var created_at = $('#time_start').val();
        var user_id = <?php echo $_GET['user_id'];?>;
        $url = "{{admin_url('history/advice')}}"+"?user_id="+user_id;
        if ( created_at ) {
            $url += "&created_at="+created_at;
        }
        window.location.href = $url;
    });

    //初始化时间插件
    $("#time_start").datetimepicker({
        minView : 2, //  选择时间时，最小可以选择到那层；默认是‘hour’也可用0表示
        language : 'zh-CN', // 语言
        autoclose : true, //  true:选择时间后窗口自动关闭
        format : 'yyyy-mm-dd', // 文本框时间格式，设置为0,最后时间格式为2017-03-23 17:00:00
        todayBtn : true, // 如果此值为true 或 "linked"，则在日期时间选择器组件的底部显示一个 "Today" 按钮用以选择当前日期。
    });
</script>

